package com.br4mmie.asciistory.ui;

import com.br4mmie.asciistory.CharImage;
import com.br4mmie.asciistory.mission.Inventory;
import com.br4mmie.asciistory.mission.InventoryItem;


/**
 * The EquipWindow shows your equipped equipment
 * @author Bram Buurlage
 *		   Pim Korschner
 */

public class EquipWindow extends Window 
{
	Inventory inventory;
	
	/**
	 * constructor
	 * @param inventory the inventory to check equipment from
	 */
	public EquipWindow(Inventory inventory) 
	{
		super(2, 2, 24, 22);
		
		this.inventory = inventory;
	}
	
	/**
	 * draws a slot
	 * @param x the x location to draw the slot on
	 * @param y the y location to draw the slot on
	 * @param center the CharImage to draw in the center of the slot
	 */
	private void drawSlot(int x, int y, CharImage center)
	{
		image.line('+', x, y, x+4, y);
		image.line('-', x+1, y, x+3, y);
		image.line('|', x, y+1, x+4, y+1);
		image.line(' ', x+1, y+1, x+3, y+1);
		image.line('+', x, y+2, x+4, y+2);
		image.line('-', x+1, y+2, x+3, y+2);
		center.draw(image, x+2, y+1);
	}
	
	/**
	 * draw the EquipWindow
	 */
	public void draw(CharImage target)
	{
		image.fill(' ');
		
		CharImage empty = new CharImage(1, 1);
		empty.fill(' ');
		CharImage[] equips = new CharImage[]                      
			{empty, empty, empty, empty, empty, empty};
		
		
		image.drawText(1, 1, 30, "Equipment");
		image.line('-', 1, 2, image.getWidth(), 2);
		
		for (InventoryItem ii: inventory.getEquiment())
		{
			if (ii.getItem().getType().equals("helmet"))
			{
				equips[0] = ii.getItem().getImage();
			}
			if (ii.getItem().getType().equals("body"))
			{
				equips[1] = ii.getItem().getImage();
			}
			if (ii.getItem().getType().equals("weapon"))
			{
				equips[2] = ii.getItem().getImage();
			}
			if (ii.getItem().getType().equals("shield"))
			{
				equips[3] = ii.getItem().getImage();
			}
			if (ii.getItem().getType().equals("legs"))
			{
				equips[4] = ii.getItem().getImage();
			}
			if (ii.getItem().getType().equals("feet"))
			{
				equips[5] = ii.getItem().getImage();
			}
		}
		
		drawSlot(9, 3, equips[0]);//helmet
		drawSlot(9, 7, equips[1]);//body
		drawSlot(3, 7, equips[2]);//weapon
		drawSlot(15, 7, equips[3]);//shield
		drawSlot(9, 11, equips[4]);//legs
		drawSlot(9, 15, equips[5]);//feet
		
		image.drawText( 1, 19, 24, "damage from items: " + inventory.getEquipDamage());
		image.drawText( 1, 20, 24, "defence from items:" + inventory.getEquipDefence());

		super.draw(target);
	}
	
	/**
	 * handle events.
	 * but there arent any.
	 */
	public void handleEvents()
	{
		super.handleEvents();
	}
}
